﻿using System; 
using System.Collections.Generic; 
using System.ComponentModel; 

namespace DataAccess{
[Serializable]
[GenWiseAttribute(IsDataSourceEntity = true) ]
public class forum_to_User : INotifyPropertyChanged
 {


#region --- Class Fields / Objects  ---

[NonSerialized]
protected PropertyChangedEventHandler _propertyChanged;
private System.Int32 _id;
private System.Int32 _id_user;
private System.Int32 _id_forum;
private forum _forum;
private user _user;

#endregion


#region --- Class Properties ---

public virtual System.Int32 id 
{
get
{
return _id;
}
}

public virtual System.Int32 id_user 
{
get
{
if ( user != null ) 
{
_id_user = (System.Int32)user.id;
}

return _id_user;
}
set 
{
if ( _id_user != value) 
{
// Simplified Parent Access Property : reset object reference if simple property changes it's value
_user = null;

_id_user = value ;
OnPropertyChanged("id_user");
}
}
}

public virtual System.Int32 id_forum 
{
get
{
if ( forum != null ) 
{
_id_forum = (System.Int32)forum.id;
}

return _id_forum;
}
set 
{
if ( _id_forum != value) 
{
// Simplified Parent Access Property : reset object reference if simple property changes it's value
_forum = null;

_id_forum = value ;
OnPropertyChanged("id_forum");
}
}
}

/// <summary>
/// Generated from Relation FK_Forum_to_User_Forum
/// </summary>
[GenWiseAttribute(RelationID = "4515b1e8-732b-4873-b086-93c6aef372b6") ]
public virtual forum forum 
{
get
{
if ( _forum == null ) 
{
if (  _id_forum.Equals(0)  || _id_forum.Equals(System.Int32.MinValue) ) 
{
if ( _forum != null && ( _forum.id.Equals(System.Int32.MinValue) ) )
{
  _forum = null;
}
}
else
{
_forum = (new forumFactory()).Get(_id_forum);
}
}

return _forum;
}
set 
{
if ( _forum != value) 
{
if ( value==null ) _id_forum = System.Int32.MinValue; else _id_forum = (System.Int32)value.id; 
_forum = value ;
}
}
}

/// <summary>
/// Generated from Relation FK_Forum_to_User_User
/// </summary>
[GenWiseAttribute(RelationID = "54ae6b5b-7a32-41ae-8543-d371ffa242e2") ]
public virtual user user 
{
get
{
if ( _user == null ) 
{
if (  _id_user.Equals(0)  || _id_user.Equals(System.Int32.MinValue) ) 
{
if ( _user != null && ( _user.id.Equals(System.Int32.MinValue) ) )
{
  _user = null;
}
}
else
{
_user = (new userFactory()).Get(_id_user);
}
}

return _user;
}
set 
{
if ( _user != value) 
{
if ( value==null ) _id_user = System.Int32.MinValue; else _id_user = (System.Int32)value.id; 
_user = value ;
}
}
}

/// <summary>
/// Is this object Valid? 
/// </summary>
/// <remarks>
/// This is achieved by counting how many errors are returned from the Validate() method. If no errors are found then it's valid.
/// </remarks>
[Bindable(false)]
public virtual System.Boolean IsValid 
{
get
{
List<Error> _errors = this.Validate(); if ( _errors.Count > 0 ) return false; else return true;
}
}


#endregion


#region --- Class Methods --- 

/// <summary>
/// Raises PropertyChanged event.
/// </summary>
protected virtual void OnPropertyChanged(System.String ppropertyChanged)
{
if (_propertyChanged != null) _propertyChanged( this , new PropertyChangedEventArgs(ppropertyChanged));

}

/// <summary>
/// Create a new forum_to_User object. 
/// </summary>
public  forum_to_User()
{
_id = System.Int32.MinValue;

}

/// <summary>
/// Validates the object returning a list of errors if the validation fails.
/// </summary>
/// <remarks>
/// You can use the provided User CodeBlocks to add your own validations.
/// </remarks>
///<returns>Returns the List of Errors found during the Validation. If no errors are found null is returned.<returns>
public virtual List<Error> Validate()
{
List<Error> _errors = new List<Error>();
return _errors;
}


#endregion


#region --- Class Events  ---

public event PropertyChangedEventHandler PropertyChanged 
{
   add {
_propertyChanged+= value;
   }
   remove {
_propertyChanged-= value;
   }
}


#endregion
}
}

